package com.cade.agriculturemall.view.classify;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.FindCallback;
import com.cade.agriculturemall.base.BasePresenter;
import com.cade.agriculturemall.model.ItemModelOfDrawerListEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lobby on 2017/11/20.
 */

public class ClassifyPresenter extends BasePresenter<ClassifyContract.IView> implements ClassifyContract.IPresenter {

    public ClassifyPresenter(ClassifyContract.IView view) {
        super(view);
    }

    @Override
    public void onResume() {
        mView.showProgress();
        AVQuery<ItemModelOfDrawerListEntity> avQuery = new AVQuery<>("ProductStructure");
//        avQuery.selectKeys(Arrays.asList("name"));
//        avQuery.orderByDescending("createAt");

        avQuery.whereExists("parentId");
        avQuery.orderByAscending("sort");
        avQuery.findInBackground(new FindCallback<ItemModelOfDrawerListEntity>() {
            @Override
            public void done(List<ItemModelOfDrawerListEntity> list, AVException e) {
                if (e == null) {
                    if (list.size() != 0) {
                        mView.onLoadMenuComplete(list);
                    }else mView.onLoadMenuComplete(new ArrayList<ItemModelOfDrawerListEntity>());
                } else {
                    e.printStackTrace();
                }
                mView.dismissProgress();
            }
        });
    }

    @Override
    public void onCreate() {

    }

    @Override
    public void onDestroy() {

    }
}
